package row

import (
	
	
	
	
	
	
	
	
	
	
	
)

// Option represents an option that can be used to configure a row.
type Option func(row *Row) error

// Row represents a dashboard row.
type Row struct {
	builder *sdk.Row
	alerts  []*alert.Alert
}

// New creates a new row.
func ( *sdk.Board,  string,  ...Option) (*Row, error) {
	 := &Row{builder: .AddRow()}

	for ,  := range append(defaults(), ...) {
		if  := ();  != nil {
			return nil, 
		}
	}

	return , nil
}

func defaults() []Option {
	return []Option{
		ShowTitle(),
	}
}

// Alerts returns a list of alerts defined within this row.
func ( *Row) () []*alert.Alert {
	return .alerts
}

// WithGraph adds a "graph" panel in the row.
// Deprecated: use WithTimeSeries() instead.
func ( string,  ...graph.Option) Option {
	return func( *Row) error {
		,  := graph.New(, ...)
		if  != nil {
			return 
		}

		.builder.Add(.Builder)

		if .Alert == nil {
			return nil
		}

		if .Builder.Datasource != nil {
			.Alert.Datasource = .Builder.Datasource.LegacyName
		}

		.alerts = append(.alerts, .Alert)

		return nil
	}
}

// WithTimeSeries adds a "timeseries" panel in the row.
func ( string,  ...timeseries.Option) Option {
	return func( *Row) error {
		,  := timeseries.New(, ...)
		if  != nil {
			return 
		}

		.builder.Add(.Builder)

		if .Alert == nil {
			return nil
		}

		if .Builder.Datasource != nil {
			.Alert.Datasource = .Builder.Datasource.LegacyName
		}

		.alerts = append(.alerts, .Alert)

		return nil
	}
}

// WithGauge adds a "gauge" panel in the row.
func ( string,  ...gauge.Option) Option {
	return func( *Row) error {
		,  := gauge.New(, ...)
		if  != nil {
			return 
		}

		.builder.Add(.Builder)

		return nil
	}
}

// WithLogs adds a "logs" panel in the row.
func ( string,  ...logs.Option) Option {
	return func( *Row) error {
		,  := logs.New(, ...)
		if  != nil {
			return 
		}

		.builder.Add(.Builder)

		return nil
	}
}

// WithSingleStat adds a "single stat" panel in the row.
// Deprecated: use WithStat() instead
func ( string,  ...singlestat.Option) Option {
	return func( *Row) error {
		,  := singlestat.New(, ...)
		if  != nil {
			return 
		}

		.builder.Add(.Builder)

		return nil
	}
}

// WithStat adds a "stat" panel in the row.
func ( string,  ...stat.Option) Option {
	return func( *Row) error {
		,  := stat.New(, ...)
		if  != nil {
			return 
		}

		.builder.Add(.Builder)

		return nil
	}
}

// WithTable adds a "table" panel in the row.
func ( string,  ...table.Option) Option {
	return func( *Row) error {
		,  := table.New(, ...)
		if  != nil {
			return 
		}

		.builder.Add(.Builder)

		return nil
	}
}

// WithText adds a "text" panel in the row.
func ( string,  ...text.Option) Option {
	return func( *Row) error {
		,  := text.New(, ...)
		if  != nil {
			return 
		}

		.builder.Add(.Builder)

		return nil
	}
}

// WithHeatmap adds a "heatmap" panel in the row.
func ( string,  ...heatmap.Option) Option {
	return func( *Row) error {
		,  := heatmap.New(, ...)
		if  != nil {
			return 
		}

		.builder.Add(.Builder)

		return nil
	}
}

// ShowTitle ensures that the title of the row will be displayed.
func () Option {
	return func( *Row) error {
		.builder.ShowTitle = true

		return nil
	}
}

// HideTitle ensures that the title of the row will NOT be displayed.
func () Option {
	return func( *Row) error {
		.builder.ShowTitle = false

		return nil
	}
}

// RepeatFor will repeat the row for all values of the given variable.
func ( string) Option {
	return func( *Row) error {
		.builder.Repeat = &

		return nil
	}
}

// Collapse makes the row collapsed by default.
func () Option {
	return func( *Row) error {
		.builder.Collapse = true

		return nil
	}
}